package server;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.AbstractTableModel;

public class StatusPanel extends JPanel {
	private static final long serialVersionUID = 1L;

	JTable table;

	public StatusPanel() {

		table = new JTable(new TableModel());

		JScrollPane scroll = new JScrollPane(table);
		scroll.setPreferredSize(new Dimension(500, 500));
		scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

		add(scroll, BorderLayout.CENTER);
	}

	private class TableModel extends AbstractTableModel {
		private static final long serialVersionUID = 1L;
		String[] nameList = { "Workstation", "Status" };
		ArrayList<RowData> rowList = new ArrayList<RowData>();

		public TableModel() {
			rowList.add(new RowData("Workstation 1", "Available"));
			rowList.add(new RowData("Workstation 2", "In Use - Locked"));
			rowList.add(new RowData("Workstation 3", "In Use - Unlocked"));
			rowList.add(new RowData("Workstation 4", "Restarting"));
			rowList.add(new RowData("Workstation 5", "Off"));
			rowList.add(new RowData("Workstation 6", "Maintenance"));
		}

		public String getColumnName(int n) {
			return nameList[n];
		}

		public int getColumnCount() {
			return nameList.length;
		}

		public int getRowCount() {
			return rowList.size();
		}

		public Object getValueAt(int row, int col) {
			RowData rowData = rowList.get(row);
			return rowData.get(col);
		}

		private class RowData {
			ArrayList<String> list = new ArrayList<String>();

			public RowData(String poste, String status) {
				list.add(poste);
				list.add(status);
			}

			public String get(int col) {
				return list.get(col);
			}
		}

	}

}
